package edu.scau.divineplace.controller;

import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.config.global.validate.annotation.NotContainBanWord;
import edu.scau.divineplace.entity.constant.ScoreConstants;
import edu.scau.divineplace.entity.enums.ScoreEnum;
import edu.scau.divineplace.entity.query.CommentScoreQuery;
import edu.scau.divineplace.entity.query.PageQuery;
import edu.scau.divineplace.entity.validate.group.commentscore.ContentAndUser;
import edu.scau.divineplace.entity.validate.group.commentscore.Id;
import edu.scau.divineplace.entity.vo.commentscore.CommentScoreGroupVO;
import edu.scau.divineplace.entity.vo.commentscore.CommentScoreVO;
import edu.scau.divineplace.entity.vo.commentscore.ContentScoreVO;
import edu.scau.divineplace.service.CommentScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2020/12/11 15:47
 */
@Slf4j
@RestController
@CrossOrigin
@Api("CommentScore控制器")
@WebLog("CommentScore控制器")
@Validated
@RequestMapping("/commentScore")
public class CommentScoreController {

    @Autowired
    private CommentScoreService commentScoreService;

    @ApiOperation("通过内容id获取内容的评分，如果userId不为null则查询用户是否点赞该评分，支持分页")
    @GetMapping("/list/{contentId}")
    public List<CommentScoreVO> list(@PathVariable Long contentId, Long userId, PageQuery pageQuery){
        return commentScoreService.list(contentId, userId, pageQuery);
    }

    @ApiOperation("通过内容id、用户id获取用户对内容的评分")
    @GetMapping("/{contentId}")
    public CommentScoreVO get(@PathVariable Long contentId, @NotNull Long userId){
        return commentScoreService.get(contentId, userId);
    }


    @ApiOperation("通过内容id获取内容的评分信息，不同评分段的人有多少")
    @GetMapping("/content/{contentId}")
    public ContentScoreVO getContentScore (@PathVariable Long contentId) {
        return commentScoreService.getContentScore(contentId);
    }

    @ApiOperation("新增评分")
    @PostMapping("/")
    public void add (@Validated(ContentAndUser.class) CommentScoreQuery query) {
        commentScoreService.add(query.getContentId(), query.getUserId(), query.getScore(), query.getComment());
    }

    @ApiOperation("修改评分")
    @PutMapping("/")
    public void update (@Validated(ContentAndUser.class) CommentScoreQuery query) {
        commentScoreService.update(query.getContentId(), query.getUserId(), query.getScore(), query.getComment());
    }

    @ApiOperation("修改评分")
    @PutMapping("/{commentScoreId}")
    public void update (@PathVariable Long commentScoreId, @Validated(Id.class) CommentScoreQuery query) {
        commentScoreService.update(commentScoreId, query.getScore(), query.getComment());
    }




}
